package com.tangkun.environment.utils;

import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Build;
import android.view.ContextThemeWrapper;

/**
 * Created Time: 2017/3/18.
 * <p>
 * Author:tangkun
 * <p>
 * 功能：创建一个ProgressDialog
 */
public class ProgressDialogUtils {
    public static ProgressDialog createProgressDialog(Context context) {
        ProgressDialog m_pDialog = new ProgressDialog(context);
        m_pDialog.setMessage("请稍后... ");
        m_pDialog.setIndeterminate(false);
        m_pDialog.setCanceledOnTouchOutside(false);
        return m_pDialog;
    }


    /**
     * 生成符合系统主题的AlertDialog.Builder
     *
     * @param context
     * @return
     */
    public static ProgressDialog getProgressDialog(Context context, boolean isLight) {
        return new ProgressDialog(
                new ContextThemeWrapper(context, getDialogTheme(isLight)));
    }

    public static ProgressDialog getProgressDialog(Context context) {
        return new ProgressDialog(
                new ContextThemeWrapper(context, getDialogTheme(true)));
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static int getDialogTheme(boolean isLight) {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
                (isLight ? android.R.style.Theme_Holo_Light_Dialog
                        : android.R.style.Theme_Holo_Dialog)
                : android.R.style.Theme_Dialog;
    }
}
